Repository navigation
[#613] Write the log context in the file adapters - #702
Merged
Merged
Conversation
The single and daily adapters write the context, without trace, as one line of JSON after the message; trace stays on its own lines. The message stays string|Stringable as PSR-3 defines, so the dead branch for array messages is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ext values that fail A trace that is not text goes into the JSON context instead of raising an Array to string conversion warning, and a context value that throws while it is converted writes a marker instead of making the log call fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
andrey-smaelov
approved these changes
Nov 22, 2026
This was referenced Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #613
What
Option 2 of the ticket: the
Loggerstays PSR-3 (the message isstring|Stringable), and thesingleanddailyadapters write the context, which they ignored.[2026-11-23 14:02:11] Info: Order paid {"order":1042}. A line without a context is unchanged.tracethat is text stays on its own lines, as before; atracethat is not text (for example$e->getTrace()) goes into the JSON instead of raising an "Array to string conversion" warning.Stringablevalue as its text, a value JSON cannot encode asnull; a value that throws while it is converted writes{"context":"not encodable"}, so a log call never fails because of its context.LoggerTrait::formatMessage()is removed;logger()->info([...])throws aTypeErroras before.messageadapter (debug bar) is unchanged.Why
The docs promised array messages, but the PSR-3 signature never allowed them, and the context had no way into the log: a failed cron task lost its
exception,fileandline. PSR-3 puts structured data in the context, so the adapters now write it.Breaking
The log line format changes when a context is passed: a tool that parses log lines must allow the JSON at the end. Values passed in the context, including secrets, now reach the log file. A custom adapter that uses
LoggerTraitmust passformatMessage()a string.Changed paths
src/Logger/Traits/LoggerTrait.phptests/Unit/Logger/Adapters/SingleAdapterTest.php,DailyAdapterTest.php,MessageAdapterTest.php,tests/Unit/Logger/LoggerTest.phpCHANGELOG.mdTesting
tracethat is not text breaks the line, and a context value that throws escapes the logger.tracethat is text, an array message throws aTypeError, themessageadapter keeps only level and message.